#ifndef STRINGPROCESSOR
#define STRINGPROCESSOR
#include <sstream>
#include <vector>
using namespace std;
class StringProcessor{
	public:
		static vector<string> explode(string, string);
		static int findcount(string, string);
		static string replace(string, string, string);
		static string replaceAll(string, string, string);
		static int atoi(const string&);
		static string atoa(const string&);
		static string itoa(const int&);
		static bool isnum(string);
		static bool isInString(char, string);
	private:			
 };
bool StringProcessor::isInString(char key, string in){
	if(in.find_first_of(key)!=string::npos)return true;
	return false;
}
bool StringProcessor::isnum(string s)
{
	istringstream iss(s);
	ostringstream oss;
	int x;
	iss >> x;
	oss << x;
	if( s == oss.str())
		return true;
	return false;
}

string StringProcessor::itoa(const int &in){
	stringstream ss;
	ss << in;
	return ss.str();
}

string StringProcessor::atoa(const string &in){
	stringstream ss;
	ss << in;
	return ss.str();
}

int StringProcessor::atoi(const string &in){
	  stringstream ss(in); // Could of course also have done ss("1234") directly.
	  int i;
	  return ss >> i? i : 0;
}

 vector<string> StringProcessor::explode(string separator, string mystring){
	 vector<string> rt;
	 string::size_type lastpos=0;
	 string::size_type pos=0;

	do{
		//cout<<"in"<<endl;
		pos=mystring.find_first_of(separator,pos);
		if(pos!=lastpos){
			if(pos!=string::npos){
				rt.push_back(mystring.substr(lastpos,pos-lastpos));
				pos+=separator.size();
				lastpos=pos;
			}
			else{
				rt.push_back(mystring.substr(lastpos,mystring.size() -lastpos));
				break;
			}
		}
		else if(pos<mystring.size()-1){
			pos+=separator.size();
			lastpos=pos;
		}
		else {
			break;
		}
	}
	while(pos>=0 && pos!=string::npos);


	return rt;
 }

 int StringProcessor::findcount(string strFind, string mystring){
	int rt=0;	
	int foundpos=0;
	do{
		foundpos=int(mystring.find(strFind,foundpos));		
		if(foundpos>=0){
			rt++;			
			foundpos++;
		}
	}
	while(foundpos>=0 && foundpos!=string::npos);
	return rt;
 }

 string StringProcessor::replace(string strFind, string strReplace, string str){

	string::size_type pos=0;
	pos=str.find(strFind,pos);
	if(pos!=string::npos){
		str.replace(pos, strFind.size(), strReplace);
	}
 	return str;
  }
 string StringProcessor::replaceAll(string strFind, string strReplace, string str){

	string::size_type pos=0;
	do{
		pos=str.find(strFind,pos);
		if(pos!=string::npos){
			str.replace(pos, strFind.size(), strReplace);
			pos++;
		}
	}
	while(pos>=0 && pos!=string::npos);
 	return str;
  }

#endif
